package com.xuelang.pipeline.artifact.entry.resource;

import com.alibaba.fastjson2.JSON;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * Nexus3V1 全局回调事件原生接口web服务
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@Slf4j
@RestController
@RequestMapping("/capability/webhook/global")
public class CapabilityWebhookGlobalController {

    /**
     * 事件回调接收接口
     *
     * @param xRequestId          请求ID，可选参数
     * @param xWebhookSignature   Webhook签名，可选参数
     * @param xNexusWebhookDelivery Nexus Webhook 传输状态，可选参数
     * @param xNexusWebhookId     Nexus Webhook ID，可选参数
     * @param payload             回调负载数据，JSON格式
     *
     * @return 返回API响应结果，无具体业务数据
     */
    @PostMapping(value = "", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> callbackCapability(
            @RequestHeader(value = "X-Request-Id", required = false) String xRequestId,
            @RequestHeader(value = "X-Webhook-Signature", required = false) String xWebhookSignature,
            @RequestHeader(value = "X-Nexus-Webhook-Delivery", required = false) String xNexusWebhookDelivery,
            @RequestHeader(value = "X-Nexus-Webhook-Id", required = false) String xNexusWebhookId,
            @RequestBody String payload) {
        log.info("xRequestId:{}, xWebhookSignature:{}, xNexusWebhookDelivery:{}, xNexusWebhookId:{}, payload:{}",
                xRequestId, xWebhookSignature, xNexusWebhookDelivery, xNexusWebhookId, JSON.toJSONString(payload));
        return ApiResponseXO.success();
    }

}
